﻿using System;
using System.Text;
using System.Collections.Generic;
using Ex03.VehicalsObjectModel;

namespace Ex03.GarageManagementSystem.Console
{
    public class GarageVehical
    {
        // Members
        private const eVehicalStatus k_InitialStatus = eVehicalStatus.UnderMaintainance;
        private Vehical m_MaintainedVehical;
        private eVehicalStatus m_VehicalStatus;
        private string m_OwnersName;

        // Ctor

        /// <summary>
        /// Creates a new GarageVehical object
        /// </summary>
        /// <param name="i_Vehical">The vehical to maintain</param>
        /// <param name="i_OwnersName">The owners of the vehical</param>
        /// <exception cref="ArgumentException">If the vehical is null or the owners name is empty</exception>
        public GarageVehical(Vehical i_Vehical, string i_OwnersName)
        {
            // Check the vehical and the owners name
            if (i_Vehical == null || i_OwnersName == string.Empty)
            {
                throw new ArgumentException("Empty owners name is not allowed");
            }
            else
            {
                m_MaintainedVehical = i_Vehical;
                m_OwnersName = i_OwnersName;
                m_VehicalStatus = k_InitialStatus;
            }
        }

        // Properties

        /// <summary>
        /// Gets the vehical under maintainance
        /// </summary>
        public Vehical MaintainedVehical
        {
            get 
            { 
                return m_MaintainedVehical; 
            }
        }

        /// <summary>
        /// Gets the vehical's owners name
        /// </summary>
        public string OwnersName
        {
            get 
            { 
                return m_OwnersName; 
            }
        }

        /// <summary>
        /// Gets the status of the maintained vehical
        /// </summary>
        public eVehicalStatus VehicalStatus
        {
            get 
            { 
                return m_VehicalStatus; 
            }
        }

        // Methods

        /// <summary>
        /// Pays for the vehical and updates its status
        /// </summary>
        public void PayForVehical()
        {
            m_VehicalStatus = eVehicalStatus.PayedFor;
        }

        /// <summary>
        /// Fixes the vehical and update its status
        /// </summary>
        /// <exception cref="ArgumentException">If the vehical is already payed for</exception>
        public void FixVehical()
        {
            // Check the status
            if (VehicalStatus == eVehicalStatus.PayedFor)
            {
                throw new ArgumentException(string.Format("The vehical {0} is already payed for", MaintainedVehical.LicenseNumber));
            }
            else
            {
                m_VehicalStatus = eVehicalStatus.Fixed;
            }
        }
    }
}
